package com.yenlien.traceyun.webase.dao;

import com.yenlien.traceyun.common.utils.LoggerUtil;
import com.yenlien.traceyun.webase.utils.CommonUtil;
import org.hibernate.transform.ResultTransformer;

import java.util.List;

/**
 * @author: bigwangy@sina.com
 * @create: 2020-06-19
 * @description:
 **/
public class SqlResultTransformer implements ResultTransformer {

    private Class resultClass;

    public SqlResultTransformer(Class clazz) {
        this.resultClass = clazz;
    }

    @Override
    public Object transformTuple(Object[] objects, String[] strings) {
        if (resultClass.equals(String.class)) {
            return objects[0];
        } else if (resultClass.equals(Integer.class)) {
            return Integer.parseInt(objects[0].toString());
        } else if (resultClass.equals(Long.class)) {
            return objects[0];
        } else {
            return CommonUtil.parse(resultClass, objects, strings);
        }
    }

    @Override
    public List transformList(List list) {
        return list;
    }
}
